package com.cloudy.cloudyspider.crawler.model;

import com.cloudy.cloudspider.search.SearchNewsModel;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * Created by cloudy.xie on 18/1/12.
 */
public class TouTiaoModel {
    private List<Data> data;

    public Set<SearchNewsModel> toNewsModel(){
        Set<SearchNewsModel> list = new HashSet<>();
        for(Data data :this.data) {
            if(data.getItem_id()==null || data.getShortContext()==null
                    || data.getTitle() == null) continue;
            list.add(SearchNewsModel.builder().author(data.getSource())
                    .title(data.getTitle()).titleImage(data.getMiddle_image())
                    .context(data.getItem_id()).time(data.getBehot_time())
                    .shortContext(data.getShortContext()).build());
        }
        return list;
    }

    public List<Data> getData() {
        return data;
    }

    public void setData(List<Data> data) {
        this.data = data;
    }

    private class Data{

        private String title;
        private String middle_image;
        private int behot_time;
        private String item_id;
        private String shortContext;
        private String source;

        public String getTitle() {
            return title;
        }

        public void setTitle(String title) {
            this.title = title;
        }

        public String getMiddle_image() {
            return middle_image;
        }

        public void setMiddle_image(String middle_image) {
            this.middle_image = middle_image;
        }

        public int getBehot_time() {
            return behot_time;
        }

        public void setBehot_time(int behot_time) {
            this.behot_time = behot_time;
        }

        public String getItem_id() {
            return item_id;
        }

        public void setItem_id(String item_id) {
            this.item_id = item_id;
        }

        public String getSource() {
            return source;
        }

        public void setSource(String source) {
            this.source = source;
        }

        public String getShortContext() {
            return shortContext;
        }

        public void setShortContext(String shortContext) {
            this.shortContext = shortContext;
        }
    }
}
